package com.laoyao.comm.config;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

public class UserIdLanjie implements Interceptor{
	public void intercept(Invocation inv) {
		 String tel="";
		 String pwd="";
		 if (inv.getController().getSessionAttr("user_tel")!=null) {
			tel=inv.getController().getSessionAttr("user_tel");
		 }
		 if (inv.getController().getSessionAttr("user_pwd")!=null) {
			pwd=inv.getController().getSessionAttr("user_pwd");
		 }
		 System.out.println("用户账号："+tel+"密码："+pwd);
		 if((tel!=null && !tel.toString().equals(""))||(pwd!=null && !pwd.toString().equals(""))){
			 String sql="select * from user where user_tel=? and user_pwd=? and user_state=0 and user_role=0";
			Record user=Db.findFirst(sql,tel,pwd);
			if (user!=null) {
				inv.getController().setSessionAttr("user_id", user.getInt("user_id"));
				inv.invoke();//放过拦截
			}else {
					 inv.getController().redirect("/ghyz");
			}
		}else{
			inv.getController().redirect("/ghyz");
		}
	}

}
